package eu.runelord.programmers.java.borderlayouttutorial;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;

class BorderLayoutExample3 extends JFrame {

	private static final long serialVersionUID = 5542988826027886015L;
	private BorderLayout borderLayout;
	private JButton n;
	private JButton s;
	private JButton w;
	private JButton e;
	private JButton c;

	public static void main(String[] args) {
		BorderLayoutExample3 borderLayoutExample = new BorderLayoutExample3();
		borderLayoutExample.setVisible(true);
	}

	public BorderLayoutExample3() {
		init();
	}

	private void init() {
		borderLayout = new BorderLayout(1, 1);
		n = new JButton("NORTH");
		s = new JButton("SOUTH");
		w = new JButton("WEST");
		e = new JButton("EAST");
		c = new JButton("CENTER");
		setLayout(borderLayout);
		setTitle("Przykład BorderLayout2");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		addComponent(n, BorderLayout.PAGE_START);
		addComponent(s, BorderLayout.SOUTH);
		addComponent(w, BorderLayout.WEST);
		addComponent(e, BorderLayout.EAST);
		addComponent(c, BorderLayout.CENTER);
		pack();
	}

	private void addComponent(JComponent component, Object constrains) {
		add(component);
		borderLayout.addLayoutComponent(component, constrains);
	}
}
